


rm(list=ls()) 


library(foreign)
library(mediation)

data<-read.dta("trim_mediation_data_ccA.dta")
attach(data)



excl_eq <- lm(excluded_sum ~ ruggbin_90+cellarea +Iccode_20+ Iccode_31+ Iccode_40+ Iccode_41+ Iccode_42+ Iccode_51+ Iccode_52+ Iccode_53+ Iccode_54+ Iccode_55+Iccode_56 +Iccode_57 +Iccode_58 +Iccode_60 +Iccode_70 +Iccode_80 +Iccode_90 +Iccode_91 +Iccode_92 +Iccode_93 +Iccode_94 +Iccode_95+Iccode_100 +Iccode_101+Iccode_110+Iccode_115+Iccode_130+Iccode_135+Iccode_140+Iccode_145+Iccode_150+Iccode_155 +Iccode_160+Iccode_165+Iccode_200+Iccode_205+Iccode_210+Iccode_211+Iccode_212+Iccode_220+Iccode_225+Iccode_230+Iccode_235+Iccode_260+Iccode_290+Iccode_305+Iccode_310+Iccode_315+Iccode_316+Iccode_317+Iccode_325+Iccode_338+Iccode_339+Iccode_341+Iccode_343+Iccode_344+Iccode_345+Iccode_346+Iccode_349+Iccode_350+Iccode_352+Iccode_355+Iccode_359+Iccode_360+Iccode_365+Iccode_366+Iccode_367+Iccode_368+Iccode_369+Iccode_370+Iccode_371+Iccode_372+Iccode_373+Iccode_375+Iccode_380+Iccode_385+Iccode_390+Iccode_395+Iccode_402+Iccode_403+Iccode_404+Iccode_411+Iccode_420+Iccode_432+Iccode_433+Iccode_434+Iccode_435+Iccode_436+Iccode_437+Iccode_438+Iccode_439+Iccode_450+Iccode_451+Iccode_452+Iccode_461+Iccode_471+Iccode_475+Iccode_481+Iccode_482+Iccode_483+Iccode_484+Iccode_490+Iccode_500+Iccode_501+Iccode_510+Iccode_516+Iccode_517+Iccode_520+Iccode_522+Iccode_530+Iccode_531+Iccode_540+Iccode_541+Iccode_551+Iccode_552+Iccode_553+Iccode_560+Iccode_565+Iccode_570+Iccode_571+Iccode_572+Iccode_580+Iccode_581+Iccode_590+Iccode_591+Iccode_600+Iccode_615+Iccode_616+Iccode_620+Iccode_625+Iccode_630+Iccode_640+Iccode_645+Iccode_651+Iccode_652+Iccode_660+Iccode_663+Iccode_666+Iccode_670+Iccode_678+Iccode_690+Iccode_692+Iccode_694+Iccode_696+Iccode_698+Iccode_700+Iccode_701+Iccode_702+Iccode_703+Iccode_704+Iccode_705+Iccode_710+Iccode_712+Iccode_713+Iccode_731+Iccode_732+Iccode_740+Iccode_750+Iccode_760+Iccode_770+Iccode_771+Iccode_775+Iccode_780+Iccode_781+Iccode_790+Iccode_800+Iccode_811+Iccode_812+Iccode_816+Iccode_820+Iccode_830+Iccode_835+Iccode_840+Iccode_850+Iccode_860+Iccode_900+Iccode_910+Iccode_920+ Iccode_935+Iccode_940+ Iccode_950+ Iccode_970+ Iccode_971+ Iccode_972+ Iccode_973+ Iccode_983+ Iccode_986+ Iccode_987+ Iccode_990, data=data)

summary(excl_eq)


civwar_eq <- lm(civwar_sum ~excluded_sum + ruggbin_90+cellarea+Iccode_20+ Iccode_31+ Iccode_40+ Iccode_41+ Iccode_42+ Iccode_51+ Iccode_52+ Iccode_53+ Iccode_54+ Iccode_55+Iccode_56 +Iccode_57 +Iccode_58 +Iccode_60 +Iccode_70 +Iccode_80 +Iccode_90 +Iccode_91 +Iccode_92 +Iccode_93 +Iccode_94 +Iccode_95+Iccode_100 +Iccode_101+Iccode_110+Iccode_115+Iccode_130+Iccode_135+Iccode_140+Iccode_145+Iccode_150+Iccode_155 +Iccode_160+Iccode_165+Iccode_200+Iccode_205+Iccode_210+Iccode_211+Iccode_212+Iccode_220+Iccode_225+Iccode_230+Iccode_235+Iccode_260+Iccode_290+Iccode_305+Iccode_310+Iccode_315+Iccode_316+Iccode_317+Iccode_325+Iccode_338+Iccode_339+Iccode_341+Iccode_343+Iccode_344+Iccode_345+Iccode_346+Iccode_349+Iccode_350+Iccode_352+Iccode_355+Iccode_359+Iccode_360+Iccode_365+Iccode_366+Iccode_367+Iccode_368+Iccode_369+Iccode_370+Iccode_371+Iccode_372+Iccode_373+Iccode_375+Iccode_380+Iccode_385+Iccode_390+Iccode_395+Iccode_402+Iccode_403+Iccode_404+Iccode_411+Iccode_420+Iccode_432+Iccode_433+Iccode_434+Iccode_435+Iccode_436+Iccode_437+Iccode_438+Iccode_439+Iccode_450+Iccode_451+Iccode_452+Iccode_461+Iccode_471+Iccode_475+Iccode_481+Iccode_482+Iccode_483+Iccode_484+Iccode_490+Iccode_500+Iccode_501+Iccode_510+Iccode_516+Iccode_517+Iccode_520+Iccode_522+Iccode_530+Iccode_531+Iccode_540+Iccode_541+Iccode_551+Iccode_552+Iccode_553+Iccode_560+Iccode_565+Iccode_570+Iccode_571+Iccode_572+Iccode_580+Iccode_581+Iccode_590+Iccode_591+Iccode_600+Iccode_615+Iccode_616+Iccode_620+Iccode_625+Iccode_630+Iccode_640+Iccode_645+Iccode_651+Iccode_652+Iccode_660+Iccode_663+Iccode_666+Iccode_670+Iccode_678+Iccode_690+Iccode_692+Iccode_694+Iccode_696+Iccode_698+Iccode_700+Iccode_701+Iccode_702+Iccode_703+Iccode_704+Iccode_705+Iccode_710+Iccode_712+Iccode_713+Iccode_731+Iccode_732+Iccode_740+Iccode_750+Iccode_760+Iccode_770+Iccode_771+Iccode_775+Iccode_780+Iccode_781+Iccode_790+Iccode_800+Iccode_811+Iccode_812+Iccode_816+Iccode_820+Iccode_830+Iccode_835+Iccode_840+Iccode_850+Iccode_860+Iccode_900+Iccode_910+Iccode_920+ Iccode_935+Iccode_940+ Iccode_950+ Iccode_970+ Iccode_971+ Iccode_972+ Iccode_973+ Iccode_983+ Iccode_986+ Iccode_987+ Iccode_990, data= data)

summary(civwar_eq)

mediation <- mediate(excl_eq, civwar_eq, sims=500, 
                    treat="ruggbin_90", mediator="excluded_sum")
summary(mediation)


####
####  NOTE: THE ESTIMATES FROM THE MEDIATION MODELS WILL DIFFER VERY SLIGHTLY EACH TIME THE MEDIATION MODELS ARE ESTIMATED AS THE ESTIMATES ARE BASED ON BOOTSTRAP DRAWS
####


